/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.sql.Timestamp;

/**
 *
 * @author Hung
 */
public class Item {

    private int id;
    private int price;
    private int luckPercent;
    private Timestamp startingTime;
    private boolean actived = false;

    public Item() {
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public void setLuckyPercent(int percent) {
        this.luckPercent = percent;
    }

    public void setStartTime(Timestamp time) {
        this.startingTime = time;
    }

    public void setActivated(int activatedId) {
        actived = (activatedId == 0 ? false : true);
    }

    public Item(int id) {
        this.id = id;
        price = ItemInfo.getItemPrice(id);
        luckPercent = ItemInfo.getItemLuckPercent(id);
//        startingTime = DateUtil.newTimestamp();
    }

    public int getId() {
        return id;
    }

    public int getPrice() {
        return price;
    }

    public int getLuckPercent() {
        return luckPercent;
    }

    public void applyItem(Timestamp time) {
        startingTime = time;
        actived = true;
    }

    public boolean isActived() {
        return actived;
    }

    public Timestamp getStartingTime() {
        if (actived) {
            return startingTime;
        } else {
            return null;
        }
    }

    public Timestamp getTime() {
        return this.startingTime;
    }

    public boolean isTimeOut() {
        if (isActived()) {
            int seconds = ItemInfo.getItemTimeLimit(id) * 3600 - (int) (System.currentTimeMillis()
                    - getStartingTime().getTime()) / 1000;
            int minutes = seconds / 60;
            if (minutes > 0) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }
}
